<?PHP
require_once("functions.php");
require_once("database.php");

session_start();

// THE FUNCTIONALITY HERE WILL EVENTUALLY BE REPLACED WITH AN AJAX POST REQUEST

// Must be logged in to set default city
if(!isset($_SESSION['user'])){
  header('location: login.php');
  exit;
}

// Verify, safe-ify and enter input
if($_GET and isset($_GET['id']) and is_numeric($_GET['id'])){

  $safe_id = sql_escape($_GET['id']);
  query_update("
    UPDATE user
    SET default_city = " . $safe_id . "
    WHERE id = " . $_SESSION['user']
  );

  header('location: city.php?id=' . $safe_id);
  exit;
}
else if($_GET and isset($_GET['reset'])){
  query_update("
    UPDATE user
    SET default_city = Null
    WHERE id= " . $_SESSION['user']
  );
  header('location: index.php');
  exit;
}

else {
  header('location: index.php');
  exit;
}




?>
